<?php
/**
 * User: 苏翔
 * Date: 2024/8/16 14:07
 */

namespace App\Dao;

use App\HscoinConf;
use App\Model\HscoinBalanceModel;
use Hyperf\Di\Annotation\Inject;

class HscoinBalanceDao extends BaseDao
{
    #[Inject]
    protected HscoinBalanceModel $model;

    function getBalance($uid = 0)
    {
        return $this->model->where('uid', $uid)->value('cnt');
    }

    function init($uid)
    {
        $today=date('Y-m-d');
        $user=$this->model->where('uid', $uid)->first();
        if(!$user){
            $this->model->insert(['uid'=>$uid,'cnt'=>0,'last_date'=>$today]);
        }

        if($today!=$user['last_date']){
            $this->model->where('uid', $uid)->update(['today_income_cnt'=>0,'last_date'=>$today]);
        }
    }
}